package org.opens.mybatisplus.controller;

import org.opens.mybatisplus.entity.EnumDemo2;
import org.opens.mybatisplus.service.EnumDemo2Service;
import org.opens.util.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (EnumDemo2)表控制层
 *
 * @author makejava
 * @since 2020-04-20 22:53:40
 */
@RestController
@RequestMapping("/api")
public class EnumDemo2Controller {
    /**
     * 服务对象
     */
    @Resource
    private EnumDemo2Service enumDemo2Service;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/enumDemo2")
    public EnumDemo2 selectOne(Integer id) {
        return this.enumDemo2Service.queryById(id);
    }

    @PostMapping(value = "/enumDemo2")
    public R save(
            @RequestBody EnumDemo2 enumDemo2
    ) {
        R success = R.success("save success");
        enumDemo2Service.insert(enumDemo2);
        success.put("data", enumDemo2);
        return success;
    }

    @PatchMapping(value = "/enumDemo2")
    public R update(
            @RequestBody EnumDemo2 enumDemo2
    ) {
        R success = R.success("update success");
        EnumDemo2 update = enumDemo2Service.update(enumDemo2);
        success.put("data", update);
        return success;
    }

    @DeleteMapping(value = "/enumDemo2/{id}")
    public R update(
            @PathVariable(value = "id") Integer id
    ) {
        R success = R.success("delete success");
        enumDemo2Service.deleteById(id);
        return success;
    }

    @GetMapping(value = "/enumDemo2/page")
    public R page() {
        R success = R.success("page success");
        List<EnumDemo2> enumDemo2s = enumDemo2Service.queryAllByLimit(0, 5);
        success.put("list", enumDemo2s);
        return success;
    }

}